<?php
class ControllerModuleNewsbox extends Controller {
	protected function index($setting) {
		
      	
				
		$this->load->model('catalog/news');
		$this->load->model('catalog/newscategory');
		$this->language->load('news/news');
		$this->load->model('tool/image');
		
		$this->data['news'] = array();
		$this->data['text_news'] = $this->language->get('text_news');
      		$this->data['text_news_not_found'] = $this->language->get('text_news_not_found');
      		$this->data['text_updated_on'] = $this->language->get('text_updated_on');
      		$this->data['text_posted_on'] = $this->language->get('text_posted_on');
                $this->data['text_read'] = $this->language->get('text_read');
                $this->data['text_times'] = $this->language->get('text_times');
         	$this->data['text_read_more'] = $this->language->get('text_read_more');
         	$this->data['text_comments'] = $this->language->get('text_comments');
		
		$results = $this->model_catalog_news->getNewss($start = 0, $limit = 40,$setting['news_category_id']);
                $category = $this->model_catalog_newscategory->getnews_category($setting['news_category_id']);
		$this->data['heading_title'] = $category['name'];
		$this->data['newss'] = array();
                foreach ($results as $result) {
      		$this->data['newss'][] = array(
        		'title' => $result['title'],
        		'date_added' => $result['date_added'],
        		'date_modified' => $result['date_modified'],
        		'description' => html_entity_decode($result['description']),
        		'short_description' => html_entity_decode($result['short_description']),
        		'count_read' => $result['count_read'],
        		'image' => $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']),
	    		'href'  => $this->url->link('news/news', 'news_id=' . $result['news_id']),
	    		//'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=news/news&news_id=' . $result['news_id']),
				'href_comment'  => $this->url->link('news/news', 'news_id=' . $result['news_id'] . '#comment_area'),
				//'href_comment'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=news/news&news_id=' . $result['news_id'] . '#comment_area'),
				'news_comment_count' =>$this->model_catalog_news->getTotalCommentsByNewsId($result['news_id'])
      		);
                }
                if($setting['position']=='content_top'||$setting['position']=='content_bottom'){
                    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/newsbox.tpl')) {
                            $this->template = $this->config->get('config_template') . '/template/module/newsbox.tpl';
                    } else {
                            $this->template = 'default/template/module/newsbox.tpl';
                    }
                }  else {
                    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/newsbox_small.tpl')) {
                            $this->template = $this->config->get('config_template') . '/template/module/newsbox_small.tpl';
                    } else {
                            $this->template = 'default/template/module/newsbox_small.tpl';
                    }                    
                }
		$this->render();
	}
}
?>